package javaLanguage.javaMultithread;

public class threadLocal {
    private static final ThreadLocal<Integer> threadLocalNum = new ThreadLocal<Integer>() {
        @Override
        protected Integer initialValue() {
            return 0;
        }
    };


    public static void main(String[] args) {
        for(int i = 0; i < 3; i ++) {
            Thread t = new Thread(new Runnable() {
                @Override
                public void run() {
                    threadLocalNum.set(threadLocalNum.get() + 1);
                    System.out.printf("%s中的值为: %d\n", Thread.currentThread().getName(), threadLocalNum.get());
                }
            });
            t.start();
        }
    }
}
